package leetcodecompetition.D371;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-11-12-11:22
 * @Description: 1.0
 */
public class T100117 {
    public int minOperations(int[] nums1, int[] nums2) {
        int n = nums1.length;
        if (n == 1) return 0;
        int cnt0 = 0, cnt1 = 1;
        for (int i = 0; i < n - 1; i++) {
            if (nums1[i] > nums1[n - 1] || nums2[i] > nums2[n - 1]) {
                if (nums1[i] > nums2[n - 1] || nums2[i] > nums1[n - 1]) {
                    return -1;
                }
                cnt0++;
            }

        }
        int ts = nums1[n - 1];
        nums1[n - 1] = nums2[n - 1];
        nums2[n - 1] = ts;
        for (int i = 0; i < n - 1; i++) {
            if (nums1[i] > nums1[n - 1] || nums2[i] > nums2[n - 1]) {
                cnt1++;
            }
        }
        System.out.println(cnt0+" "+cnt1);
        return Math.min(cnt0, cnt1);
    }
}
